package 工厂模式.工厂方法模式.controller;

import 工厂模式.工厂方法模式.factory.FreeGoodsFactoryMap;
import 工厂模式.工厂方法模式.factory.impl.DiscountFreeGoodsFactory;
import 工厂模式.工厂方法模式.factory.FreeGoodsFactory;
import 工厂模式.工厂方法模式.factory.impl.SmallGiftGoodsFactory;
import 工厂模式.简单工厂.entity.AwardInfo;
import 工厂模式.简单工厂.entity.ResponseResult;
import 工厂模式.简单工厂.service.IFreeGoods;

import java.util.HashMap;

public class DeliverController {
    public static void main(String[] args) {
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setUid("1001");
        awardInfo.setAwardTypes(3);
        awardInfo.setAwardNumber("SMS10001");
        HashMap<String, String> map = new HashMap<>();
        map.put("username","王五");
        map.put("phone","123456789");
        map.put("address","北京");
        awardInfo.setExtMap(map);
        deliverGoods(awardInfo);
    }

    public static ResponseResult deliverGoods(AwardInfo awardInfo){
//        FreeGoodsFactory factory = null;
//        if (awardInfo.getAwardTypes() == 1){
//            factory = new DiscountFreeGoodsFactory();
//        } else if (awardInfo.getAwardTypes() == 2) {
//            factory = new SmallGiftGoodsFactory();
//        }
        // 根据类型获取具体工厂
        FreeGoodsFactory factory = FreeGoodsFactoryMap.getParserFactory(awardInfo.getAwardTypes());
        // 从工厂类中获取对于的实列
        System.out.println("=======工厂方法模式输出=======");
        assert factory != null;
        IFreeGoods freeGoods = factory.getInstance();
        return freeGoods.sendFreeGoods(awardInfo);
    }
}
